package com.fatgirl.core
{

	/**
	 * 绑定结构解析 内部工厂 
	 * 
	 * XML实例：
	 * <?xml version="1.0" encoding="utf-8"?>
		<bindData>
		 	<item cname="ui.mediator::MainViewMediator" info="主界面">
		 		<bind obj="this" objPro="setLittleMapPos" data="metas.MyData" dataPro="usPosXY"/>
		 	</item>
		 	<item cname="ui.mediator::ChooseUserViewMediator" info="选择角色界面">
		 		<bind obj="this" objPro="setRoleList" data="metas.LoginData" dataPro="roleInfoList"/>
		 	</item>		
		</bindData>
	 * @author iceman
	 * 
	 */
	public class MediatorBindFactory
	{
		private static var s_BindFactory:MediatorBindFactory;
		private var m_IMetaFactory:IMetaFactory;
		private var m_bingDataList:Array;
		private var m_cfgXML:XML;
		public function MediatorBindFactory()
		{
			if(s_BindFactory) throwError(this,FatError.SINGLETON_CLASS);
			m_bingDataList = new Array;
		}
		public static function getInstance():MediatorBindFactory
		{
			if(!s_BindFactory) s_BindFactory = new MediatorBindFactory;
			return s_BindFactory;
		}
		public function init(_xml:XML,_IMetaFactory:IMetaFactory):void
		{
			m_IMetaFactory = _IMetaFactory;
			m_cfgXML = _xml;
		}
		public function getMetaFactory():IMetaFactory
		{
			return m_IMetaFactory;
		}
		public function getBindData(_cName:String):Vector.<MediatorBindData>
		{
			if(!m_bingDataList[_cName])
			{
				if(!m_cfgXML) return null;
				var t_xmlList:XMLList = m_cfgXML.item.(@cname == _cName);
				if(t_xmlList)
				{
					var t_xml:XML = t_xmlList[0];
					if(t_xml && t_xml.bind)
					{
						var t_vec:Vector.<MediatorBindData> = new Vector.<MediatorBindData>;
						for(var i:int = 0;i<t_xml.bind.length();i++)
						{	
							var t_MediatorBindData:MediatorBindData = new MediatorBindData;
							t_MediatorBindData.obj = t_xml.bind[i].@obj;
							t_MediatorBindData.objPro = t_xml.bind[i].@objPro;
							t_MediatorBindData.data = t_xml.bind[i].@data;
							t_MediatorBindData.dataPro = t_xml.bind[i].@dataPro;
							t_vec.push(t_MediatorBindData);		
						}
						m_bingDataList[_cName] = t_vec;
					}
				}
			}
			return m_bingDataList[_cName];
		}
	}
}